<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class MYLang {
	private $CI;
	function __construct() {
		$this->CI = & get_instance ();
		$this->CI->load->library ( 'lang' );
		$this->CI->load->library ( 'mysession' );
		$this->CI->config->load ( 'config' );
	}
	function load($lang_filename = 'admin') {
		$language = $this->getLanguage ();
		$this->CI->lang->load ( $lang_filename, $language );
		return $language;
	}
	function setLanguage($language) {
		if (! $language) {
			$language = $this->getDefaultLanguage ();
		}
		$this->CI->mysession->setLanguage ( $language );
		return $language;
	}
	function getLanguage() {
		$language = $this->CI->mysession->getLanguage();
		if (! $language) {
			$language = $this->getDefaultLanguage ();
		}
		return $language;
	}
	function getDefaultLanguage() {
		$language = $this->CI->config->item ( CONFIG_KEY_LANGUAGE );
		return $language;
	}
	function __call($method_name, $args) {
		echo 'Undefined function: '.__CLASS__ .'->'. $method_name.'()';
		exit;
	}
	
}

